﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using MyFinanceManager.Objects;

namespace MyFinanceManager.PC
{
    public enum KindOf
    {
        Einnahme,
        Ausgabe,
        Auswertung,
        Einstellungen,
        Transfers,
        Home
    }

    /// <summary>
    /// Interaction logic for WindowNewStyle.xaml
    /// </summary>
    public partial class WindowNewStyle : Window
    {
        Brush taskbarBlue = null;
        Brush taskbarBlack = null;
        Brush taskbarOrange = null;
        Brush taskbarGreen = null;
        Brush taskbarYellow = null;
        Brush taskbarCurrent = null;

        ImageSource headerBlue = null;
        ImageSource headerOrange = null;
        ImageSource headerGreen = null;
        ImageSource headerYellow = null;
        ImageSource headerBlack = null;
        ImageSource headerCurrent = null;

        public WindowNewStyle()
        {
            // Needed cause my pc thinks he lives in the united states. 
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");

            InitializeComponent();

            taskbarBlue = this.FindResource("VistaTaskbarBlue") as Brush;
            taskbarBlack = this.FindResource("VistaTaskbarBlack") as Brush;
            taskbarOrange = this.FindResource("VistaTaskbarOrange") as Brush;
            taskbarGreen = this.FindResource("VistaTaskbarGreen") as Brush;
            taskbarYellow = this.FindResource("VistaTaskbarYellow") as Brush;
            taskbarCurrent = this.stackPanelBar.Background;

            headerBlue = new BitmapImage(new Uri(@"\Pics\HeaderBlue.jpg", UriKind.RelativeOrAbsolute));
            headerBlack = new BitmapImage(new Uri(@"\Pics\HeaderBlack.jpg", UriKind.RelativeOrAbsolute));
            headerOrange = new BitmapImage(new Uri(@"\Pics\HeaderOrange.jpg", UriKind.RelativeOrAbsolute));
            headerGreen = new BitmapImage(new Uri(@"\Pics\HeaderGreen.jpg", UriKind.RelativeOrAbsolute));
            headerYellow = new BitmapImage(new Uri(@"\Pics\HeaderYellow.jpg", UriKind.RelativeOrAbsolute));
            headerCurrent = this.headerPic.Source;

            this.pageExpenses.itemsArea.ItemsSource = RepositoryCenter.Repositoy.Expenses;
            this.pageExpenses.FilenameCategories = Filenames.FilenameCategoryEx;
            this.pageEarnings.itemsArea.ItemsSource = RepositoryCenter.Repositoy.Earnings;
            this.pageEarnings.FilenameCategories = Filenames.FilenameCategoryIn;
            this.pageTransfers.itemsArea.ItemsSource = RepositoryCenter.Repositoy.Transfers;
            this.pageFuel.itemsArea.ItemsSource = RepositoryCenter.Repositoy.Fuels;
        }

        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            KindOf ko = GetKindOf(sender);

            switch (ko)
            {
                case KindOf.Einnahme:
                    this.stackPanelBar.Background = this.taskbarGreen;
                    this.headerPic.Source = this.headerGreen;
                    break;
                case KindOf.Ausgabe:
                    this.stackPanelBar.Background = this.taskbarOrange;
                    this.headerPic.Source = this.headerOrange;
                    break;
                case KindOf.Auswertung:
                    this.stackPanelBar.Background = this.taskbarBlue;
                    this.headerPic.Source = this.headerBlue;
                    break;
                case KindOf.Transfers:
                    this.stackPanelBar.Background = this.taskbarYellow;
                    this.headerPic.Source = this.headerYellow;
                    break;
                default:
                    this.stackPanelBar.Background = this.taskbarBlack;
                    this.headerPic.Source = this.headerBlack;
                    break;
            }
        }

        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            this.stackPanelBar.Background = this.taskbarCurrent;
            this.headerPic.Source = this.headerCurrent;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.taskbarCurrent = this.stackPanelBar.Background;
            this.headerCurrent = this.headerPic.Source;

            foreach (var item in this.LayoutRoot.Children)
            {
                if (item is UserControl)
                {
                    ((UserControl)item).Visibility = Visibility.Hidden;
                }
            }

            KindOf ko = GetKindOf(sender);

            switch (ko)
            {
                case KindOf.Einnahme:
                    this.pageEarnings.Visibility = Visibility.Visible;
                    break;
                case KindOf.Ausgabe:
                    this.pageExpenses.Visibility = Visibility.Visible;
                    break;
                case KindOf.Auswertung:
                    this.pageAuswertung.Visibility = Visibility.Visible;
                    break;
                case KindOf.Transfers:
                    this.pageTransfers.Visibility = Visibility.Visible;
                    break;
                case KindOf.Einstellungen:
                    this.pageFuel.Visibility = Visibility.Visible;
                    break;
                default:
                    this.pageStart.Visibility = Visibility.Visible;
                    break;
            }

        }

        private static KindOf GetKindOf(object sender)
        {
            string tag = (string)((Button)sender).Tag;

            KindOf ko = KindOf.Home;
            try
            {
                ko = (KindOf)Enum.Parse(typeof(KindOf), tag);
            }
            catch
            {
                ko = KindOf.Home;
            }
            return ko;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //RepositoryCenter.Repositoy.Save();
        }
    }
}
